﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Lottery.Herper;

namespace Lottery.MediaData.UI {
    /// <summary>
    /// 修改限制范围
    /// </summary>
    public partial class EditLimitForm : Form {
        private int max;

        public EditLimitForm(string limit, int max)
            : this() {
            this.Limit = limit;
            this.max = max;

            editLow.Items.Clear();
            for (int i = 0; i < max + 1; i++) {
                editLow.Items.Add(i.ToString());
            }

            editUp.Items.Clear();
            for (int i = 0; i < max + 1; i++) {
                editUp.Items.Add(i.ToString());
            }

            var t = Limit.Split('-');
            editLow.SelectedIndex = editLow.Items.IndexOf(t[0]);
            editUp.SelectedIndex = editUp.Items.IndexOf(t[1]);
        }

        private EditLimitForm() {
            InitializeComponent();
            
            editLow.JumpToNext = editUp;
            editUp.JumpToNext = buttonOK;

            this.SetDialogStyle();
        }

        /// <summary>
        /// 限制范围
        /// </summary>
        public string Limit { get; set; }

        private void buttonCancel_Click(object sender, EventArgs e) {
            DialogResult = DialogResult.Cancel;
        }

        private void buttonOK_Click(object sender, EventArgs e) {
            if (editLow.SelectedIndex == -1) {
                this.ShowInfo("没有输入下限");
                editLow.Focus();
                return;
            }

            if (editUp.SelectedIndex == -1) {
                this.ShowInfo("没有输入上限");
                editUp.Focus();
                return;
            }

            if (editLow.SelectedIndex > editUp.SelectedIndex) {
                this.ShowInfo("下限不能大于上限");
                editLow.Focus();
                return;
            }

            Limit = string.Format("{0}-{1}", editLow.Text, editUp.Text);

            DialogResult = DialogResult.OK;
        }
    }
}
